package com.gy.smart.mine;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.gy.smart.R;
import com.gy.smart.base.BaseActivity;
import com.gy.smart.base.BaseBean;
import com.gy.smart.util.RequestResultListener;
import com.gy.smart.util.Urls;

import org.xutils.http.RequestParams;

/**
 * 作者：gy on 17/1/5
 * 说明：
 */
public class LoginActivity extends BaseActivity {

    private EditText etName,etPass;
    private TextView tvLogin;
    private String strName,strPas;

    @Override
    protected void initView() {
        setContentViewRes(R.layout.activity_login);
        hidenTop();
        etName = (EditText) findViewById(R.id.activity_login_et_name);
        etPass = (EditText) findViewById(R.id.activity_login_et_pass);
        tvLogin = (TextView) findViewById(R.id.activity_login_tv_login);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {
        super.setListener();
        tvLogin.setOnClickListener(this);
    }

    @Override
    public void doClick(View v) {
        super.doClick(v);
        switch (v.getId()){
            case R.id.activity_login_tv_login:
                strName = etName.getText().toString().trim();
                strPas = etPass.getText().toString().trim();
                if(TextUtils.isEmpty(strName)){
                    showToast("请输入用户名");
                } else if(TextUtils.isEmpty(strPas)){
                    showToast("请输入密码");
                } else if(strName.length() != 11){
                    showToast("请输入正确的用户名");
                } else {
                    requestLogin();
                }
                break;
        }
    }

    /** 登录*/
    private void requestLogin(){
        showLoadDialog();
        RequestParams params = new RequestParams(Urls.url_login);
        params.addParameter("mobile",strName);
        params.addParameter("password",strPas);
        postRequest(params, new RequestResultListener() {
            @Override
            public boolean onSuccess(BaseBean result) {
                if(result.status == 1){

                }
                return false;
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }
        });
    }
}
